package com.hdax.dm.controller;

import com.hdax.dm.dto.LoginDto;
import com.hdax.dm.exception.DmException;
import com.hdax.dm.service.LoginService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private LoginService loginService;

    //手机号登录
    @PostMapping("login")
    public CommonResponse<LoginDto> login(@RequestBody Map<String,String> map){
        return loginService.login(map.get("phone"),map.get("password"));
    }

    //异常处理
    @ExceptionHandler(value = {DmException.class})
    public CommonResponse<String> dmExceptionHandler(DmException e){
        return ResponseUtil.returnFail(e);
    }
}
